package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import cn.sdhuijin.healthexam.DatabaseHelper;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 新建人员档案-最后一页
 * 
 * @author houyuchun
 * 
 */
public class EditPersonDocLastActivity extends AbstractControlActivity
		implements OnClickListener {

	// 创建日期ID
	private String createDate;
	private DatabaseHelper databaseHelper;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 去掉标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_edit_doc_last);

		ExitApplication.getInstance().addActivity(this);
		databaseHelper = new DatabaseHelper(this);
		Intent intent = getIntent();
		// 创建日期ID
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);
		// 厨房排风设施
		addRadioGroupView(R.id.rad_chufangpaifeng, "厨房排风设施");
		// 燃料类型
		// addRadioGroupView(R.id.rad_ranliaoleixing, "燃料类型");
		addRadioEditUnionView(new int[] { R.id.edt_rllx_other }, "燃料类型",
				new String[] { "燃料类型-其他" }, R.id.rad_ranliaoleixing, "其他");
		// 饮水
		// addRadioGroupView(R.id.rad_yinshui, "饮水");
		addRadioEditUnionView(new int[] { R.id.edt_ys_other }, "饮水",
				new String[] { "饮水-其他" }, R.id.rad_yinshui, "其他");
		// 厕所
		addRadioGroupView(R.id.rad_cesuo, "厕所");
		// 禽畜栏
		addRadioGroupView(R.id.rad_qinchulan, "禽畜栏");
		// Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(EditPersonDocLastActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		this.setButtonListener(this, R.id.btn_complete, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, EditPersonDocForthActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_complete:
			controlManager.toProperties();
			// 更新索引表
			databaseHelper.updateIndexTable(createDate);
			this.toastInformation(R.string.toast_submit_info);
			intent.setClass(this, IndexActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}
}
